//
//  OilCardSlideDialDetailViewController.m
//  JxCarios
//
//  Created by phev on 15/2/13.
//  Copyright (c) 2015年 xiongchuanqi. All rights reserved.
//

#import "OilCardSlideDialDetailViewController.h"
#define CURRENDATASOUCE [[_tableDataSource objectAtIndex:_currenPage] customObjectForkey:@"detial"]
static NSString *cell = @"oilCardSlideDia";

@interface OilCardSlideDialDetailViewController () <UITableViewDataSource,UITableViewDelegate>

@end

@implementation OilCardSlideDialDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.hidden = YES;
    [self initAbout];
    [self netRequst];
}

- (void)netRequst {
    if (!_carAround) {
        _carAround = [CarAroundDataSource dataSourceWithRequestor:self];
    }
    _carAround.oilCard = _oilCardNum;
    [_carAround oilCardDetail:^(id result) {
        _currenPage = 0;
        _tableDataSource = [result customObjectForkey:@"info"];
        _currenDataSource = [[_tableDataSource firstObject] customObjectForkey:@"detial"];
        [self initDataSource];
    } anfFail:^(id result) {
        
    }];
    
}

- (void)initDataSource {
    if (_tableDataSource.count <= 0 && _cardInfo.count <= 0) {
        [self.navigationController.view makeToast:@"此油卡无划拨纪录" duration:1.0f position:TOP_POINT];
        return;
    }
    [self setUpSlideDiaHeadDetail];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.hidden = NO;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView reloadData];
}

- (void)setUpSlideDiaHeadDetail {
    _cardInfo = [[_tableDataSource objectAtIndex:_currenPage] customObjectForkey:@"card"];
    _dateLabel.text = [_cardInfo customObjectForkey:@"DAO_KUAN_DATE"];
    _priceLabel.text = [RMB stringByAppendingString:[_cardInfo customObjectForkey:@"SET_MONEY"]];
    _countLabel.text = [NSString stringWithFormat:@"%ld",[_tableDataSource count]];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [CURRENDATASOUCE count] <= 0 ? 0 :  [CURRENDATASOUCE count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OilCardSlideDiaCell *oil = [tableView dequeueReusableCellWithIdentifier:cell forIndexPath:indexPath];
    _currenDataSource = CURRENDATASOUCE;
    oil.count = [[[_currenDataSource objectAtIndex:indexPath.row]customObjectForkey:@"PI_CI"] integerValue];
    oil.date.text = [[_currenDataSource objectAtIndex:indexPath.row] customObjectForkey:@"HUABO_DATE"];
    oil.price.text = [RMB stringByAppendingString:[[_currenDataSource objectAtIndex:indexPath.row] customObjectForkey:@"HUABO_MONEY"]];
    return oil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}


- (void)initAbout {
    self.title = @"划拨详情";
    [self showNavBarWithRightTitle:nil andRightAction:nil andLeftAction:nil andCustom:NO];
    _OnABusiness.transform = CGAffineTransformRotate(self.OnABusiness.transform, M_PI);
    [self.tableView registerNib:[UINib nibWithNibName:@"OilCardSlideDiaCell" bundle:nil] forCellReuseIdentifier:cell];
    _titleArr = @[@"套餐业务一",@"套餐业务二",@"套餐业务三",@"套餐业务四",@"套餐业务五",@"套餐业务六",@"套餐业务七",@"套餐业务八",@"套餐业务九",@"套餐业务十",@"套餐业务十一",@"套餐业务十二",@"套餐业务十三",@"套餐业务十四",@"套餐业务十五",@"套餐业务十六",@"套餐业务十七",@"套餐业务十八",@"套餐业务十八",@"套餐业务十九",@"套餐业务二十",@"套餐业务二十一",@"套餐业务二十二",@"套餐业务二十三",@"套餐业务二十四",@"套餐业务二十五",@"套餐业务二十六",@"套餐业务二十七",@"套餐业务二十八",@"套餐业务二十九",@"套餐业务三十",@"套餐业务三十一",@"套餐业务三十二",@"套餐业务三十三",@"套餐业务三十四",@"套餐业务三十五",@"套餐业务三十六",@"套餐业务三十七",@"套餐业务三十八",@"套餐业务三十九",@"套餐业务四十",@"套餐业务四十一",@"套餐业务四十二",@"套餐业务四十三",@"套餐业务四十四",@"套餐业务四十五",@"套餐业务四十六",@"套餐业务四十七",@"套餐业务四十八",@"套餐业务四十九"];
     
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)onABusinessAction:(id)sender {
    _currenPage --;
    if (_currenPage <= -1) {
        _currenPage = 0;
        _OnABusiness.hidden = YES;

    }else{
        _nameLabel.text = [_titleArr objectAtIndex:_currenPage];
        [self.tableView reloadData];
        [self setUpSlideDiaHeadDetail];

    }
}

- (IBAction)nextBusinessAction:(id)sender {
    if (_tableDataSource.count <= 1) {
        [self.navigationController.view makeToast:@"没有更多油卡业务了,亲！" duration:1.5f position:TOP_POINT];
        return;
    }
    
    _OnABusiness.hidden = NO;
    _currenPage++;
    if (_currenPage < _tableDataSource.count) {
        [self setUpSlideDiaHeadDetail];
        _nameLabel.text = [_titleArr objectAtIndex:_currenPage];
        [_tableView reloadData];
    }else{
        [self.navigationController.view makeToast:@"没有更多油卡业务了,亲！" duration:1.5f position:TOP_POINT];
        _currenPage--;
    }

}
@end
